package com.squapsource.project_euler;

import org.apache.commons.lang.StringUtils;

public class Problem4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(findLargestPalidrome(999,99));

	}

	private static int findLargestPalidrome(int largestFactor, int smallestFactor) {
		int result = 0;
		for (int i = largestFactor; i > smallestFactor; i--) {
			for (int j = largestFactor; j > smallestFactor; j--) {
				if (isPalindrome(i * j) && i * j > result) {
					result = i * j;
				}

			}

		}
		return result;
	}

	private static boolean isPalindrome(int palindrome) {
		return Integer.toString(palindrome).equals(
				StringUtils.reverse(Integer.toString(palindrome)));
	}

}
